// 页面初始化
$(function () {

    // 页脚高度
    // parseInt( $('#group').css('height') ) > parseInt( $('#trends').css('height') ) ? (function(){
    //     $('#trends').css('height', $('#group').css('height') );
    //  })() : (function () {
    //     $('#group').css('height', $('#trends').css('height') );
    // })();

    $('#trends').css('min-height', $('#group').css('height') );

    /********************************************************************/
    /********************************************************************/

    initPage();

    // 页面初始化
    function initPage(){
        dataOBJ.pageSize = 7;
        let Pr_adList = new Promise( (resolve, reject)=>{
            $.ajax({
                type: 'post',
                url : '/announcemen/list_announcemen.do',
                data : {
                    pageNum : dataOBJ.pageNum,
                    pageSize : dataOBJ.pageSize,
                    startTime : '',
                    stopTime : '',
                    name : ''
                },
                dataType : 'json',
                xhrFields : {
                    withCredentials: true
                },
                crossDomain: true,
                success: function (data) {
                    if(data.status == 0){
                        resolve( data );
                    }else if(data.status == 10){
                        reject( data );
                    }
                }
            });
        } );
        let Pr_adNavBar = new Promise( (resolve, reject)=>{
            $.ajax({
                type: 'post',
                url : '/projectDetails/get_excellent_works.do',
                data : {},
                dataType : 'json',
                xhrFields : {
                    withCredentials: true
                },
                crossDomain: true,
                success: function (data) {
                    if(data.status == 0){
                        resolve( data );
                    }else if(data.status == 10){
                        reject( data );
                    }
                }
            });
        } );
        let all_Pr = Promise.all( [Pr_adList,Pr_adNavBar] );
        all_Pr.then( (data)=>{
            // 渲染公告列表
            To_AdList( data[0].data.list );
            // 优秀项目
            To_youXiu( data[1].data );
        } ).catch( (data)=>{
            spop_waring( data.msg );
        })
    }
    function To_youXiu(aData) {
        $('#Youxiu').html('');
        aData.forEach( function (item,idx) {
            let DOM = $('<div class="swiper-slide">' +
                    '<a href="/look-item.html?projectno='+ item.projectno +'">' +
                    '<img class="swiper-lazy" data-src="'+ item.coverurl +'"/>' +
                    '</a>' +
                '</div>');
            DOM.appendTo( $('#Youxiu') );
        } );
        // 优秀作品
        var swiper = new Swiper('.swiper-container_2', {
            loop:true,// 环路
            autoplay:true,// 自动播放

            centerInsufficientSlides:true,// 小于居中
            slidesPerView: 5,// 同时显示个数
            spaceBetween: 30,// 间隔
            slidesPerGroup : 1,// 一组几个

            lazy: {
                loadPrevNext: true,// 延迟加载应用到最接近
            },
            on:{
                lazyImageLoad: function(slideEl, imageEl){
                    $(slideEl).css({
                        width : '197.6px'
                    });
                }
            },

            navigation: {
                nextEl: '.swiper-button-next_2',
                prevEl: '.swiper-button-prev_2',
            },
        });
    }

    // 轮播图
    var mySwiper = new Swiper ('#banner', {
        loop: true,
        autoplay : true,
        effect : 'fade',
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },

        lazy: {
            loadPrevNext: true,
            loadPrevNextAmount: 1,
            loadOnTransitionStart: true,
        },
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        autoHeight : true
    });

});